#pragma once

#include <iostream>
#include <string>
#include <vector>
#include <unistd.h>
#include <unordered_map>
#include <string>
#include <functional>

typedef std::function<void()> func;
// using func = std::function<void()>;
std::vector<func> callBack;
std::unordered_map<int, std::string> desc;

void readMySQL(){
    std::cout << "process[ " << getpid() << " ] 执行访问数据库的任务！" << std::endl;
}

void execuleUrl(){
    std::cout << "process[ " << getpid() << " ] 执行了 Url 的解析任务！" << std::endl;
}

void cal(){
    std::cout << "process[ " << getpid() << " ] 执行数据加密任务！" << std::endl;
}

void save(){
    std::cout << "process[ " << getpid() << " ] 执行数据持久化任务！" << std::endl;
}

void load(){
    desc.insert({callBack.size(), "readMySQL：访问数据库！"});
    callBack.push_back(readMySQL);

    desc.insert({callBack.size(), "execuleUrl：解析 Url！"});
    callBack.push_back(execuleUrl);

    desc.insert({callBack.size(), "readMySQL：数据加密！"});
    callBack.push_back(cal);

    desc.insert({callBack.size(), "readMySQL：数据持久化！"});
    callBack.push_back(save);
}

void showHandler(){
    for(const auto &iter : desc){
        std::cout << iter.first << "\t" << iter.second << std::endl;
    }
}

int HandlertaskSize(){
    return callBack.size();
}